package com.jxwifi.cloud.quickclean.app;

import android.app.Activity;

import java.lang.ref.WeakReference;

/**
 * Created by lisi on 2016/6/6.
 */
public class MyActivityManager {
    private static MyActivityManager sInstance = new MyActivityManager();
    private WeakReference<Activity> sCurrentActivityWeakRef;
    private WeakReference<Class<? extends Activity>> mCurrentActivityClassRef;

    private MyActivityManager() {
    }

    public static MyActivityManager getInstance() {
        return sInstance;
    }

    public Activity getCurrentActivity() {
        Activity currentActivity = null;
        if (sCurrentActivityWeakRef != null) {
            currentActivity = sCurrentActivityWeakRef.get();
        }
        return currentActivity;
    }

    public Class<? extends Activity> getCurrentActivityClass() {
        Class<? extends Activity> currentClass = null;
        if (mCurrentActivityClassRef != null) {
            currentClass = mCurrentActivityClassRef.get();
        }
        return currentClass;
    }

    public void setCurrentActivity(Activity activity) {
        sCurrentActivityWeakRef = new WeakReference<Activity>(activity);
        mCurrentActivityClassRef = new WeakReference<Class<? extends Activity>>(activity.getClass());

//        //获取Activity的className
//        String activityStr = activity.toString();
//        activityStr.substring(activityStr.lastIndexOf(".") + 1, activityStr.indexOf("@"));
    }
}
